import type { PostLoginData } from '@/types/common'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'user',
  () => {
    // 用户 token
    const token = ref('')

    // 设置 token
    const setToken = (newToken: string) => {
      token.value = newToken
    }

    // 清除 token
    const clearToken = () => {
      token.value = ''
    }

    //用户信息
    const userInfo = ref<PostLoginData>()
    const setUserInfo = (value: PostLoginData) => {
      userInfo.value = value
    }

    const clearUserInfo = () => {
      userInfo.value = undefined
    }

    return {
      token,
      setToken,
      clearToken,
      userInfo,
      setUserInfo,
      clearUserInfo,
    }
  },
  {
    persist: true,
  }
)
